<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      class="search-form"
    >
      <el-form-item label="人才姓名" prop="talentName">
        <el-input
          v-model="queryParams.talentName"
          placeholder="请输入人才姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执业资格证注册等级" prop="registrationLevel">
        <el-input
          v-model="queryParams.registrationLevel"
          placeholder="请输入执业资格证注册等级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技术职称" prop="technicalTitle">
        <el-select v-model="queryParams.technicalTitle" placeholder="请选择技术职称" clearable>
          <el-option
            v-for="dict in dict.type.technical_title"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          style="margin-left: 50px;"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button size="mini" @click="toggleSearchBar">
          <i class="el-icon-circle-plus-outline" style="font-size: 13px"></i>
        </el-button>
      </el-form-item>

      <!-- 点击加号后显示的全部搜索框 -->
      <div v-show="showSearchBar">
        <el-form-item label="出生日期" prop="birthDate">
          <el-date-picker v-model="queryParams.birthDate" placeholder="请选择出生日期" clearable></el-date-picker>
        </el-form-item>

        <el-form-item label="参加工作起始时间" prop="startWorkTime">
          <el-date-picker v-model="queryParams.startWorkTime" placeholder="请选择参加工作开始时间" clearable></el-date-picker>
        </el-form-item>

        <br />

        <el-form-item label="学历" prop="educationLevel">
          <el-select v-model="queryParams.educationLevel" placeholder="请选择学历" clearable>
            <el-option
              v-for="dict in dict.type.education_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="毕业院校" prop="graduateSchool">
          <el-input
            v-model="queryParams.graduateSchool"
            placeholder="请输入毕业院校"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="专业" prop="majorStudy">
          <el-input
            v-model="queryParams.majorStudy"
            placeholder="请输入专业"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:library:add']"
        >新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="libraryList" @selection-change="handleSelectionChange">
      <el-table-column label="序号" align="center">
        <template
          slot-scope="scope"
        >{{ (scope.$index + 1) + ((queryParams.pageNum - 1) * queryParams.pageSize) }}</template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="talentName" />
      <el-table-column label="出生日期" align="center" prop="birthDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学历" align="center" prop="educationLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.education_level" :value="scope.row.educationLevel" />
        </template>
      </el-table-column>
      <el-table-column label="执业资格证注册等级" align="center" prop="registrationLevel" />
      <el-table-column label="技术职称" align="center" prop="technicalTitle">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.technical_title" :value="scope.row.technicalTitle" />
        </template>
      </el-table-column>
      <el-table-column label="参加工作起始时间" align="center" prop="startWorkTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startWorkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="毕业院校" align="center" prop="graduationSchool" />
      <el-table-column label="所学专业" align="center" prop="majorStudy" />
      <!-- <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="280">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="warning"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:library:edit']"
            style="width:60px;"
          >修改</el-button>
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:library:remove']"
            style="width:60px;"
          >删除</el-button>
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-setting"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:library:remove']"
            style="width:60px;"
          >详情</el-button>
          <el-button
            size="mini"
            type="success"
            icon="el-icon-folder"
            @click="handleAttachment(scope.row)"
            v-hasPermi="['system:library:remove']"
            style="width:60px;"
          >附件</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加/修改 对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <div style="margin : 3vh 0">
        <el-steps :active="activeStep" align-center>
          <el-step title="基本信息"></el-step>
          <el-step title="证件信息"></el-step>
          <el-step title="公路建设监督系统辅助信息"></el-step>
        </el-steps>
      </div>

      <div v-if="activeStep === 0" class="add-talent-information-form">
        <div class="add-title">基本信息</div>
        <div style="margin:0 117px">
          <el-form ref="form" :model="form" :rules="rules" label-width="118px" :inline="true">
            <el-form-item label="人才姓名" prop="talentName">
              <el-input v-model="form.talentName" placeholder="请输入人才姓名" />
            </el-form-item>
            <el-form-item label="出生日期" prop="birthDate">
              <el-date-picker
                clearable
                v-model="form.birthDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择出生日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="学历" prop="educationLevel">
              <el-select v-model="form.educationLevel" placeholder="请选择学历" clearable>
                <el-option
                  v-for="dict in dict.type.education_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="技术职称" prop="technicalTitle">
              <el-select v-model="form.technicalTitle" placeholder="请选择技术职称" clearable>
                <el-option
                  v-for="dict in dict.type.technical_title"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="参加工作开始时间" prop="startWorkTime">
              <el-date-picker
                clearable
                v-model="form.startWorkTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择参加工作开始时间"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="从事勘察设计工作起始时间" prop="startSurveyDesignTime">
              <el-date-picker
                clearable
                v-model="form.startSurveyDesignTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择从事勘察设计工作起始时间"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="毕业院校" prop="graduationSchool">
              <el-input v-model="form.graduationSchool" placeholder="请输入毕业院校" />
            </el-form-item>
            <el-form-item label="毕业时间" prop="graduationTime">
              <el-date-picker
                clearable
                v-model="form.graduationTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择毕业时间"
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="所学专业" prop="majorStudy">
              <el-input v-model="form.majorStudy" placeholder="请输入所学专业" />
            </el-form-item>
            <el-form-item label="学制" prop="educationDuration">
              <el-input v-model="form.educationDuration" placeholder="请输入学制" />
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-form>
        </div>
      </div>

      <div v-if="activeStep === 1" class="add-talent-ducument-form">
        <div class="add-title">证件信息</div>
        <document></document>
      </div>

      <div v-if="activeStep === 2" class="add-talent-ducument-form">
        <div class="add-title">公路建设监督辅助系统</div>
        <road></road>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button @click="prevStep">上一步</el-button>
        <el-button @click="nextStep">下一步</el-button>
        <el-button type="primary" @click="submitForm">立即保存</el-button>
      </span>
    </el-dialog>

    <!-- 详情对话框 -->
    <el-dialog title="人才库信息详情" :visible.sync="detailDialogVisible" width="1000px">
      <div class="detail-button">
        <el-button type="primary" plain size="mini" @click="activeTab = 'basicInfo'">基本信息</el-button>
        <el-button type="primary" plain size="mini" @click="activeTab = 'certificateInfo'">证件信息</el-button>
        <el-button type="primary" plain size="mini" @click="activeTab = 'projectInfo'">项目业绩</el-button>
        <el-button type="primary" plain size="mini" @click="activeTab = 'honorInfo'">荣誉信息</el-button>
        <el-button
          type="primary"
          plain
          size="mini"
          @click="activeTab = 'supervisionInfo'"
        >公路建设监督系统辅助信息</el-button>
      </div>

      <div class="detail-title" v-show="activeTab === 'basicInfo'">基本信息</div>
      <div style="margin:0 117px" v-show="activeTab === 'basicInfo'">
        <el-form ref="form" :model="form" :rules="rules" label-width="118px" :inline="true">
          <el-form-item label="人才姓名" prop="talentName">
            <el-input v-model="form.talentName" placeholder="请输入人才姓名" />
          </el-form-item>
          <el-form-item label="出生日期" prop="birthDate">
            <el-date-picker
              clearable
              v-model="form.birthDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择出生日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="学历" prop="educationLevel">
            <el-select v-model="form.educationLevel" placeholder="请选择学历" clearable>
              <el-option
                v-for="dict in dict.type.education_level"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="技术职称" prop="technicalTitle">
            <el-select v-model="form.technicalTitle" placeholder="请选择技术职称" clearable>
              <el-option
                v-for="dict in dict.type.technical_title"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="参加工作开始时间" prop="startWorkTime">
            <el-date-picker
              clearable
              v-model="form.startWorkTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择参加工作开始时间"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="从事勘察设计工作起始时间" prop="startSurveyDesignTime">
            <el-date-picker
              clearable
              v-model="form.startSurveyDesignTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择从事勘察设计工作起始时间"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="毕业院校" prop="graduationSchool">
            <el-input v-model="form.graduationSchool" placeholder="请输入毕业院校" />
          </el-form-item>
          <el-form-item label="毕业时间" prop="graduationTime">
            <el-date-picker
              clearable
              v-model="form.graduationTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择毕业时间"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="所学专业" prop="majorStudy">
            <el-input v-model="form.majorStudy" placeholder="请输入所学专业" />
          </el-form-item>
          <el-form-item label="学制" prop="educationDuration">
            <el-input v-model="form.educationDuration" placeholder="请输入学制" />
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" placeholder="请输入备注" />
          </el-form-item>
        </el-form>
      </div>

      <div class="detail-title" v-show="activeTab === 'certificateInfo'">证件信息</div>
      <div v-show="activeTab === 'certificateInfo'">
        <detail-document :row="selectedRow"></detail-document>
      </div>

      <div class="detail-title" v-show="activeTab==='projectInfo'">项目业绩</div>
      <div v-show="activeTab==='projectInfo'">
        <detail-performance :row="selectedRow"></detail-performance>
      </div>

      <div class="detail-title" v-show="activeTab==='honorInfo'">荣誉信息</div>
      <div v-show="activeTab==='honorInfo'">
        <detail-honor :row="selectedRow"></detail-honor>
      </div>

      <div class="detail-title" v-show="activeTab==='supervisionInfo'">公路建设监督系统辅助信息</div>
      <div v-show="activeTab==='supervisionInfo'">
        <detail-road :row="selectedRow"></detail-road>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="detailDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="detailDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 附件对话框 -->
    <el-dialog title="全部附件" :visible.sync="AttachmentDialogVisible" width="800px">
      <attachment></attachment>
      <span slot="footer" class="dialog-footer">
        <el-button @click="AttachmentDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="AttachmentDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  listLibrary,
  getLibrary,
  delLibrary,
  addLibrary,
  updateLibrary
} from "@/api/system/library";
import Document from "@/views/system/document";
import Road from "@/views/system/road";
import DetailRoad from "@/views/system/detailRoad";
import DetailDocument from "@/views/system/detailDocument";
import Performance from "@/views/system/performance";
import Honor from "@/views/system/honor";
import Attachment from "@/views/system/Attachment";
import DetailPerformance from "@/views/system/detailPerformance";
import DetailHonor from "@/views/system/detailHonor";

export default {
  components: {
    Document,
    Road,
    DetailDocument,
    Performance,
    Honor,
    Attachment,
    DetailRoad,
    DetailPerformance,
    DetailHonor
  },
  name: "Talent",
  // 用于使用字典映射数据，如education_level字段的 10中专 20本科 30研究生 40博士，从后端10,20,30,40映射到前端的中专,本科,研究生,博士
  dicts: ["education_level", "technical_title"],
  data() {
    return {
      // 存储选中的row
      selectedRow: null,
      //控制显示详情按钮
      showDetailsCard: false,
      // 默认显示基本信息
      activeTab: "basicInfo",
      // 详情对话框的显示状态
      detailDialogVisible: false,
      AttachmentDialogVisible: false,
      // 控制搜索框的显示状态
      showSearchBar: false,
      // 新增步骤条
      activeStep: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      libraryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        talentName: null,
        registrationLevel: null,
        birthDate: null,
        educationLevel: null,
        technicalTitle: null,
        startWorkTime: null,
        graduationSchool: null,
        majorStudy: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        seq: [
          {
            required: true,
            message: "序号(用于显示的顺序）不能为空",
            trigger: "blur"
          }
        ],
        updateUser: [
          { required: true, message: "更新人不能为空", trigger: "blur" }
        ],
        updateDate: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        talentName: [
          { required: true, message: "人才姓名不能为空", trigger: "blur" }
        ],
        birthDate: [
          { required: true, message: "出生日期不能为空", trigger: "blur" }
        ],
        educationLevel: [
          { required: true, message: "学历不能为空", trigger: "blur" }
        ],
        technicalTitle: [
          { required: true, message: "技术职称不能为空", trigger: "blur" }
        ],
        startWorkTime: [
          {
            required: true,
            message: "参加工作开始时间不能为空",
            trigger: "blur"
          }
        ],
        startSurveyDesignTime: [
          {
            required: true,
            message: "从事勘察设计工作起始时间不能为空",
            trigger: "blur"
          }
        ],
        graduationSchool: [
          { required: true, message: "毕业院校不能为空", trigger: "blur" }
        ],
        graduationTime: [
          { required: true, message: "毕业时间不能为空", trigger: "blur" }
        ],
        majorStudy: [
          { required: true, message: "所学专业不能为空", trigger: "blur" }
        ],
        educationDuration: [
          { required: true, message: "学制不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  computed: {
    dialogTitle() {
      return `步骤${this.activeStep}`;
    }
  },
  methods: {
    // 点击加号切换搜索框显示状态
    toggleSearchBar() {
      this.showSearchBar = !this.showSearchBar;
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listLibrary(this.queryParams).then(response => {
        this.libraryList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      console.log("打印一下");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        talentName: null,
        birthDate: null,
        educationLevel: null,
        technicalTitle: null,
        startWorkTime: null,
        startSurveyDesignTime: null,
        graduationSchool: null,
        graduationTime: null,
        majorStudy: null,
        educationDuration: null,
        seq: null,
        remark: null,
        createUser: null,
        createTime: null,
        updateUser: null,
        updateDate: null,
        status: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "人才库信息新增";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getLibrary(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "人才库信息修改";
      });
    },
    // 处理详情按钮
    handleDetail(row) {
      this.selectedRow = row; // 存储当前行的数据
      console.log("selectedRow:", this.selectedRow); // 打印 selectedRow 的值
      this.reset();
      const id = row.id || this.ids;
      getLibrary(id).then(response => {
        this.form = response.data;
        this.detailDialogVisible = true; // 显示对话框
        this.title = "人才库信息详情";
      });
      console.log("111详情");
    },
    // 处理附件
    handleAttachment(row) {
      this.reset();
      this.AttachmentDialogVisible = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLibrary(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLibrary(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？')
        .then(function() {
          return delLibrary(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/library/export",
        {
          ...this.queryParams
        },
        `library_${new Date().getTime()}.xlsx`
      );
    },
    prevStep() {
      if (this.activeStep > 0) {
        this.activeStep--;
      }
    },

    nextStep() {
      if (this.activeStep < 2) {
        this.activeStep++;
      }
    },
    handleSubmit() {
      // 处理表单提交逻辑
      console.log(this.currentForm);
      this.dialogVisible = false;
    }
  }
};
</script>


<style>
/* 根据姓名、职业资格证名称、技术职称查询人才 */
.search-form .el-form-item__label {
  /* font: normal normal 14px "Helvetica Neue"; */
  padding: 0 12px 0 60px !important;
}

.search-form {
  margin: 2vh 0 2vh 0;
}

/* 添加和修改人才表单 */
.add-talent-information-form .el-form-item__label,
.add-talent-ducument-form .el-form-item__label,
.add-talent-ducument-form .el-form-item__label {
  font: normal normal 12px "Helvetica Neue";
  padding: 0 12px 0 0px !important;
}

.add-talent-information-form,
.add-talent-ducument-form,
.add-talent-ducument-form {
  padding: 3vh 0 0 0;
  border: 2px solid #c0c4cc;
  border-radius: 2px;
}

.add-title {
  font: bold 18px "Microsoft YaHei", sans-serif;
  color: #1890ff;
  padding: 0 0 2vh 2vw !important;
}
.detail-title {
  font: bold 18px "Microsoft YaHei", sans-serif;
  color: #1890ff;
  padding: 4vh 0 4vh 2vw !important;
}
</style>
